using System;
using System.Collections.Generic;
using System.Text;
using DataTools;
using DataTools.PagingUtils;
using ObjectLayer;

namespace CommonAccessLayer
{
	public class ethnicsDAO
{
		public static List<ethnicsBO> GetAll()
		{
			return CBO.FillCollection<ethnicsBO>(DataProvider.getInstance().getAll(TableName.ethnics, PagingHelper.CreateOrder(new OrderObject(ethnicsTable.id, SortOrder.Desc))));
		}
		static object _Clock = new object();
		public static List<ethnicsBO> GetAllC()
		{
			List<ethnicsBO> list = new List<ethnicsBO>();
			if(DataCache.GetCache(CacheName.ethnics) == null)
			{
				lock (_Clock)
				{
					if (DataCache.GetCache(CacheName.ethnics) != null)
					{
						list = (List<ethnicsBO>)DataCache.GetCache(CacheName.ethnics);
					}
					else
					{
			list = CBO.FillCollection<ethnicsBO>(DataProvider.getInstance().getAll(TableName.ethnics, PagingHelper.CreateOrder(new OrderObject(ethnicsTable.id, SortOrder.Desc))));
						DataCache.SetCache(CacheName.ethnics, list);
					}
				}
			}
			else
			{
					list = (List<ethnicsBO>)DataCache.GetCache(CacheName.ethnics);
			}
		return list;
		}
		public static int InsertUpdateDelete(ethnicsBO ethnics, ProviderAction action)
		{
			int rs = DataProvider.getInstance().InsertUpdateDelete(action, StoreProcedureName.InsertUpdateDelete_ethnics, "@" + ethnicsTable.id, ethnics.id,ethnics.name, DataTools.ConvertType.ToInt(action));
			if (rs != -1)
			{
				DataCache.RemoveCache(CacheName.ethnics);
			}
			return rs;
		}
		public static int Insert(ethnicsBO ethnics)
		{
			 return InsertUpdateDelete(ethnics, ProviderAction.Insert);
		}
		public static int Update(ethnicsBO ethnics)
		{
			 return InsertUpdateDelete(ethnics, ProviderAction.Update);
		}
		public static int Delete(ethnicsBO ethnics)
		{
			 return InsertUpdateDelete(ethnics, ProviderAction.Delete);
		}
		public static int Delete(int id)
		{
			ethnicsBO ethnics = new ethnicsBO(id);
			return Delete(ethnics);
		}
	}
}